package com.beta.restapi.controller;

import com.beta.common.web.ContentType;
import com.beta.entity.HomeRecommends;
import com.beta.restapi.internal.Consts;
import com.beta.service.IHomeBannersService;
import com.beta.service.IHomeRecommendsService;
import com.beta.vo.home.HomeBannersVO;
import com.beta.vo.home.HomeRecommendsVO;
import com.beta.entity.HomeBanners;
import io.swagger.annotations.Api;
import ma.glasnost.orika.MapperFacade;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * Created by lichao on 2016/12/20.
 */
@Api(tags = "Home")
@RestController
@RequestMapping(Consts.API_PATH_PREFIX)
public class HomeController extends BaseController {

    @Autowired
    private MapperFacade beenMapper;
    @Autowired
    private IHomeBannersService homeBannersService;
    @Autowired
    private IHomeRecommendsService homeRecommendsService;

    @GetMapping(value = "/home_banners", produces = ContentType.JSON)
    public Object homeBanners(@RequestHeader(Consts.HEADER_AUTH_KEY) String token) {
        List<HomeBanners> homeBanners = homeBannersService.getHomeBanners(getCurrentUser());
        List<HomeBannersVO> homeBannersVOs = beenMapper.mapAsList(homeBanners, HomeBannersVO.class);
        return ok(homeBannersVOs);
    }

    @GetMapping(value = "/home_recommends", produces = ContentType.JSON)
    public Object homeRecommends(@RequestHeader(Consts.HEADER_AUTH_KEY) String token) {
        List<HomeRecommends> homeRecommends = homeRecommendsService.getHomeRecommends(getCurrentUser());
        List<HomeRecommendsVO> homeRecommendsVOs = beenMapper.mapAsList(homeRecommends, HomeRecommendsVO.class);
        return ok(homeRecommendsVOs);
    }

}
